package com.sunny.thread.synchronizedpack; /**
 * Created by Sunny on 2016/11/16.
 */

/**
 * num2
 *
 * @author sunc
 * @date 2016-11-16-10:24
 */
public class HasSelfPrivateNum2  {

    private int num = 0 ;
    private String name;
    public HasSelfPrivateNum2(String name){
        this.name = name;
    }


    synchronized public void addI() {
        try {
            if (name.equals("a")) {
                num = 100;
                System.out.println(Thread.currentThread().getName()+"a set over");
                Thread.sleep(200);
            } else {
                num = 200;
                System.out.println(Thread.currentThread().getName()+"b set over");
            }
            System.out.println(Thread.currentThread().getName()+",name="+name+" ,num="+num);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    synchronized  public void minusI(){
        try {
            if (name.equals("a")) {
                num = 10;
                System.out.println(Thread.currentThread().getName()+"minus a set over");
                Thread.sleep(200);
            } else {
                num = 20;
                System.out.println(Thread.currentThread().getName()+"minus b set over");
            }
            System.out.println(Thread.currentThread().getName()+",name="+name+" ,num="+num);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

}
